package com.PVZ.model.weapon;

import com.PVZ.controller.SoundController;
import com.PVZ.model.Entity;
import com.PVZ.model.bullet.Bullet;
import com.PVZ.model.emuns.AnimeType;
import com.PVZ.model.emuns.Configs;
import com.PVZ.model.emuns.EffectType;
import com.PVZ.model.emuns.ZombieType;
import com.PVZ.model.zombie.Zombie;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * Created by @Author: kabuda on @Date: 2021/5/18 19:49
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Weapon {


    private Boolean isBoobed=false;

    private Bullet bullet;

    //武器效果
    private EffectType effect;

    /**
     * 冷却时间 单位 s
     */
    private int coolDown, curCoolTime = 0;

    /**
     * 是否 发射  发射后才会进入冷却
     */
    private Boolean hasShoot = false;

    //一次发射几发
    private int shootNum;

    private int hasShootNum = 0;

    /**
     * 单位 格
     * 最大为15
     */
    private int attackFiled;

    public void attack(Entity attacker, List<Entity> enemies) {

        boolean attackOk = true;
        if (getCurCoolTime() == 0) {
            if (!getHasShoot()) {
                //冷却完毕 可以攻击
                if (this instanceof Bite) {
                    Entity enemy = enemies.get(0);
                    enemy.setHealth(enemy.getHealth() - Configs.demages.get(((Zombie) attacker).getZombieType()));
                    SoundController.playSound("eat.wav", SoundController.ONCE);
                }
                setHasShoot(true);
            }
        }else {
            setHasShoot(false);
        }

        for (Entity enemy : enemies) {
            if (enemy.health>0) {
                attackOk = false;
                break;
            }
        }
        if (attackOk) {
            ((Zombie) attacker).startMove();
        }


    }

    public Weapon(Bullet bullet, EffectType effect, int coolDown, int attackFiled) {
        this.bullet = bullet;
        this.effect = effect;
        this.coolDown = coolDown;
        this.attackFiled = attackFiled;
    }

}
